<?php
namespace Admin\Controller;
use Think\Controller;

class VideoCopyController extends Controller{

    public function index(){
        set_time_limit(0);
        $column_type  = M("vrnews1.news_column",null);
        $video_column = $column_type->where("name = '视频'")->field('column_id')->find();
        $news_video   = M("vrnews1.news_video", null);
        $news      = M("vrnews1.news",null);
        $news_list = $news->join("vrnews1.news_video on vrnews1.news_video.news_id = vrnews1.news.news_id", 'left')->where("type = 4 and column_id != '".$video_column['column_id']."'")->select();
        if($news_list){
            foreach ($news_list as $key=>$value){
                $data  = array();
                $video = array();
                $news_id = time().$this->getRange();
                $data['news_id'] = $news_id;
                $data['title']    		  = $value['title'];
                $data['subtitle'] 		  = $value['subtitle'];
                $data['keywords']		  = $value['keywords'];
                $data['source_id']		  = $value['source_id'];
                $data['source_name'] 	  = $value['source_name'];
                $data['tags'] 			  = $value['tags'];
                $data['type'] 			  = $value['type'];
                $data['column_id'] 		  = $video_column['column_id'];
                $data['abstract'] 		  = $value['abstract'];
                $data['cover_image'] 	  = $value['cover_image'];
                $data['content'] 		  = $value['content'];
                $data['outer_url'] 		  = $value['outer_url'];
                $data['outer_url_ishot']  = $value['outer_url_ishot'];
                $data['app_pub'] 		  = $value['app_pub'];
                $data['web_pub'] 	 	  = $value['web_pub'];
                $data['weight'] 		  = $value['weight'];
                $data['top_status'] 	  = $value['top_status'];
                $data['full_status'] 	  = $value['full_status'];
                $data['full_title'] 	  = $value['full_title'];
                $data['full_subtitle']	  = $value['full_subtitle'];
                $data['full_cover_image'] = $value['full_cover_image'];
                $data['reference_id']	  = $value['reference_id'];
                $data['reference_type']   = $value['reference_type'];
                $data['create_time']      = $value['create_time'];
                $data['refresh_time']     = $value['refresh_time'];
                $data['update_time']      = $value['update_time'];
                $data['special_news_id']  = $value['special_news_id'];
                $data['click_count']      = $value['click_count'];
                $data['creator_id']       = $value['creator_id'];
                $data['creator_name']     = $value['creator_name'];
                $data['competitor_id']    = $value['competitor_id'];
                $data['special_entry']    = $value['special_entry'];
                $data['special_id']       = $value['special_id'];
                $data['special_type']     = $value['special_type'];
                $data['special_title']    = $value['special_title'];
                $data['special_abstract'] = $value['special_abstract'];
                $data['special_image']    = $value['special_image'];
                $data['live_id']          = $value['live_id'];
                $data['live_status']      = $value['live_status'];
                $data['vote_id']          = $value['vote_id'];
                $news->add($data);
                $video['news_id']       = $news_id;
                $video['thumbnail_url'] = $value['thumbnail_url'];
                $video['file_name']     = $value['file_name'];
                $video['file_id']       = $value['file_id'];
                $video['video_url']     = $value['video_url'];
                $video['video_url1']    = $value['video_url1'];
                $video['video_url2']    = $value['video_url2'];
                $video['duration']      = $value['duration'];
                $video['height']        = $value['height'];
                $video['height1']       = $value['height1'];
                $video['height2']       = $value['height2'];
                $video['width']         = $value['width'];
                $video['width1']        = $value['width1'];
                $video['width2']        = $value['width2'];
                $video['size']          = $value['size'];
                $video['size1']         = $value['size1'];
                $video['size2']         = $value['size2'];
                $video['category']      = $value['category'];
                $video['play_count']    = $value['play_count'] ? $value['play_count'] : 0;
                $video['update_time']   = $value['update_time'];
                $video['text']          = $value['text'];
                $video['status']        = $value['status'];
                $news_video->add($video);
            }
        }
    }

    function getRange($cnt=9){
        $numbers = range (1,$cnt);
        //播下随机数发生器种子，可有可无，测试后对结果没有影响
        srand ((float)microtime()*1000000);
        shuffle ($numbers);
        //跳过list第一个值（保存的是索引）
        $n = '';
        while (list(, $number) = each ($numbers)) {
            $n .="$number";
        }
        return $n;
    }

}